<?php
define('BANNER_TYPE_SWF'		,	'IMG');
define('BANNER_TYPE_IMG'		,	'SWF');
define('BANNER_TARGET_SELF'		,	'SELF');
define('BANNER_TARGET_BLANK'	,	'_BLANK');
class Cl_Banner extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$banner_seq			= 0					,	//	
		$banner_code		= ''				,	//	
		$banner_name		= ''				,	//	
		$banner_type		= BANNER_TYPE_IMG	,	//	
		$banner_file		= ''				,	//	
		$banner_link		= ''				,	//	
		$banner_width		= 0					,	//	
		$banner_height		= 0					,	//	
		$banner_target		= BANNER_TARGET_SELF,	//	
		$banner_use_flag	= 'T'				,	//	
		$banner_insert_time	= 0					,	//	
		$banner_del_flag	= 'F'				;	//	
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($banner_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($banner_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
		if(is_string($this->banner_file))
		{
			$this->banner_file = (array) json_decode($this->banner_file, 1);
		}
	}
	
	/**
	 * 
	 */
	public function autoUpdate($log='')
	{
		if((int)$this->banner_seq > 0)
		{
			$this->update($log);
		}
		else
		{
			$this->insert($log);
		}
	}
	
	/**
	 *	
	 */
	public function insert($log='Insert')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		
		$this->banner_use_flag		= 'T';
		$this->banner_insert_time	= time();
		$this->banner_del_flag		= 'F';
		
		$data = array(	'banner_code'			=>	$this->banner_code,
						'banner_name'			=>	$this->banner_name,
						'banner_type'			=>	$this->banner_type,
						'banner_file'			=>	json_encode((array) $this->banner_file),
						'banner_link'			=>	$this->banner_link,
						'banner_width'			=>	$this->banner_width,
						'banner_height'			=>	$this->banner_height,
						'banner_target'			=>	$this->banner_target,
						'banner_use_flag'		=>	$this->banner_use_flag,
						'banner_insert_time'	=>	$this->banner_insert_time,
						'banner_del_flag'		=>	$this->banner_del_flag
					);
		$this->banner_seq = $dbo->insert($data);
		$this->backup($log);
	}
	
	/**
	 * 
	 */
	public function update($log='update')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		
		$data = array(	'banner_name'			=>	$this->banner_name,
						'banner_type'			=>	$this->banner_type,
						'banner_file'			=>	json_encode((array) $this->banner_file),
						'banner_link'			=>	$this->banner_link,
						'banner_width'			=>	$this->banner_width,
						'banner_height'			=>	$this->banner_height,
						'banner_target'			=>	$this->banner_target,
						'banner_use_flag'		=>	$this->banner_use_flag
					);
		$dbo->update($data, array("banner_seq = ".$this->banner_seq));
		$this->backup($log);
	}
	
	/**
	 * 
	 */
	public function delete($log='delete')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->delete(array("banner_seq = ".$this->banner_seq));
		$this->backup($log);
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
// 		/*------------------------------------------------------------*/
// 		$dbo = self::getDbo();
// 		/*------------------------------------------------------------*/
// 		$dbo->log($this->user_seq, $log, $this->backup_data);
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}